<?php 
class ControllerInformationThongTin extends Controller {
	public function index() {  
		$this->load->model('tool/seo_url');
		$this->load->model('catalog/information');
		$this->language->load('information/information');
		
		$this->document->breadcrumbs = array();
		
      	$this->document->breadcrumbs[] = array(
        	'href'      => $this->model_tool_seo_url->rewrite($this->url->http('common/home')),
        	'text'      => $this->language->get('text_home'),
        	'separator' => FALSE
      	);

		
		$information_info = $this->model_catalog_information->getInformations();
   		
		if ($information_info) {
			$this->document->title = $this->language->get('text_thongtin');
			$this->data['heading_title'] = $this->language->get('text_thongtin');
      		$this->document->breadcrumbs[] = array(
        		'href'      => $this->model_tool_seo_url->rewrite($this->url->http('information/thongtin')),
        		'text'      => "Thông tin",
        		'separator' => $this->language->get('text_separator')
      		);
			
			$this->data['informations'] = array();

			foreach ($information_info as $result) {
				$first_img = '';
				$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'), $matches);
				if($matches [1]){
				$first_img = $matches [1] [0];
				} else {
				$first_img = "image/no_image.jpg";
				}
				$this->data['informations'][] = array(
					'title' 		 => $result['title'],
					'description' => $result['description'],
					'image'     => $first_img,
					'href'  		 => $this->model_tool_seo_url->rewrite($this->url->http('information/information&information_id=' . $result['information_id']))
				);
			}
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/thongtin.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/information/thongtin.tpl';
			} else {
				$this->template = 'default/template/information/thongtin.tpl';
			}
			
			$this->children = array(
				'common/header',
				'common/footer',
				'common/column_left',
				'common/column_right'
			);		
			
	  		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
    	} else {
      		$this->document->breadcrumbs[] = array(
        		'href'      => $this->model_tool_seo_url->rewrite($this->url->http('information/thongtin')),
        		'text'      => $this->language->get('text_error'),
        		'separator' => $this->language->get('text_separator')
      		);
				
	  		$this->document->title = $this->language->get('text_error');
			
      		$this->data['heading_title'] = $this->language->get('text_error');

      		$this->data['text_error'] = $this->language->get('text_error');

      		$this->data['button_continue'] = $this->language->get('button_continue');

      		$this->data['continue'] = $this->url->http('common/home');

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
			} else {
				$this->template = 'default/template/error/not_found.tpl';
			}
			
			$this->children = array(
				'common/header',
				'common/footer',
				'common/column_left',
				'common/column_right'
			);
		
	  		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
    	}
  	}
}
?>